<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Cp1251">
<title>Insert title here</title>
</head>
	<?php
		if (isset($_POST['register1'])) {
			$name = $_POST['regName'];
			$pass = md5($_POST['regPass']);
			$money = $_POST['money'];
			$db_connect = mysqli_connect("localhost" , "root" , "" , "tractor");
			$query = "insert into users (username, pass, money) values (\"$name\" , \"$pass\" , \"$money\")";
			$querySelect = "select username from users";
			$result = mysqli_query($db_connect,$querySelect);
			$flag = true;
			if (mysqli_num_rows($result) > 0) {
				while($row = mysqli_fetch_assoc($result)){
					if ($row['username'] == $name) {
						
						$flag = false;
					}
				}
			}
			if ($flag) {
				mysqli_query($db_connect,$query);
				session_start();
				$_SESSION['name'] = $name;
				header("Location: index.php");
			}
			else
			{
				echo "Name already exists";
			}
			mysqli_close($db_connect);
		} 
	?>
    <body>
    <form method="post" action="register.php">
    	Login:<input name="regName"><br/>
    	Passwor:<input type="password" name="regPass"><br/>
    	Money:<input name="money"><br/>
    	<input type="submit" value="register" name="register1"> 
    </form>
    </body>
</html>